import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';
import 'package:myapp/main_router.dart';
import 'package:myapp/util/toast_util.dart';

class TabIndex extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("首页"),
        centerTitle: true,
        leading: IconButton(
          icon: const Icon(Icons.qr_code_scanner),
          onPressed: () {
            ToastUtil.show(context, "扫一扫");
          },
        ),
        actions: <Widget>[
          IconButton(
            icon: const Icon(Icons.add),
            onPressed: () {
              final tc = Get.find<TokenController>();
              tc.handleTokenInvalid();
            },
          ),
        ],
      ),
      body: _Tab(),
    );
  }
}

class _Tab extends StatelessWidget {
  const _Tab();

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Container(
          width: 200,
          height: 100,
          child: ElevatedButton(
            onPressed: () {
              ToastUtil.show(context, "111222333");
            },
            child: Text("测试按钮1"),
          ),
        ),
        Container(
          width: 200,
          height: 50,
          child: ElevatedButton(
            onPressed: () {
              play();
            },
            child: Text("测试按钮2"),
          ),
        )
      ],
    );
  }

  void play() {

    EasyLoading.show(status: 'loading...');
    Future.delayed(Duration(seconds: 2),(){
      EasyLoading.dismiss();
    });
    // var l = AppLoginRequest().setParams("test01", "123456").execute();
    // l.then((value) => {
    //       print(value.data!.accessToken),
    //       print("111111"),
    //       print("222222"),
    //     });
  }
}
